package sg.edu.nus.iss.vmcs.service;

import sg.edu.nus.iss.vmcs.customer.CustomerPanel;
import sg.edu.nus.iss.vmcs.languagesupport.LanguagerProperty;

public class TransactionDisplayService implements ITransactionDisplayService{
	private CustomerPanel custPanel;
	
	private static TransactionDisplayService instance;
	
	/**
	 * Return new VMCS Instance
	 * @return
	 */
	public static TransactionDisplayService getInstance(){
		
		if(instance==null){
			instance = new TransactionDisplayService();
		}
	
		return instance;
	}
	/**
	 * Set the customer panel
	 * @param custPanel
	 */
	public void setCustPanel(CustomerPanel custPanel) {
		if(custPanel!=null){
			this.custPanel = custPanel;
		}
	}
	/**
	 * Initiate the customer panel to start the coin receiver
	 */
	public void startCoinReceiver(){
		custPanel.setCoinInputBoxActive(true);
		custPanel.setTotalMoneyInserted(0);
	}
	/**
	 * Set the coin input box status
	 */
	public void setCoinInputBox(boolean active){
		custPanel.setCoinInputBoxActive(active);
	}
	
	public void stopReceiveCoin(){
		if(custPanel==null){
			return;
		}
		custPanel.setCoinInputBoxActive(false);
	}
	/**
	 * On received coin failed
	 */
	public void onReceivedCoinFail(){
		custPanel.displayInvalidCoin(true);
		custPanel.setChange(LanguagerProperty.getLanguagerProperties().getProperty("invalid.coin"));
	}
	/**
	 * On received coin success
	 */
	public void onReceivedCoinSuccess(int insertedCoin){
		custPanel.setCoinInputBoxActive(false);
		custPanel.displayInvalidCoin(false);
		custPanel.setTotalMoneyInserted(insertedCoin);
		custPanel.setChange("");
	}
	public void refundCash(int sertedCoin){
		custPanel.setChange(sertedCoin);
		custPanel.setTotalMoneyInserted(0);
		custPanel.displayInvalidCoin(false);
	}
	/**
	 * Set the total money inserted
	 * @param money
	 */
	public void setTotalMoneyInserted(int money){
		custPanel.setTotalMoneyInserted(money);
	}
	/**
	 * Display the customer panel
	 */
	public void displayCustomerPanel(){
		custPanel.display();
	}
	public void setCustomerPanelTerminateButton(boolean activate){
		custPanel.setTerminateButtonActive(activate);
	}
	/**
	 * Set the customer panel change label
	 * @param change
	 */
	public void setChange(int change){
		custPanel.setChange(change);
	}
	/**
	 * Reset the change
	 */
	public void resetChange(){
		if(custPanel!=null){
			custPanel.resetChange();
		}
	}
	/**
	 * Close down the customer panel
	 */
	public void closeDownCustPanel(){
		if (custPanel != null)
			custPanel.closeDown();
	}
	/**
	 * Terminate the transaction service for the customer panel
	 */
	public void terminateTransactionServiceForCustomerPanel(){
		if(custPanel!=null){
			custPanel.setTerminateButtonActive(false);
		}
	}
	/**
	 * Display the change status
	 * @param status
	 */
	public void displayChangeStatus(boolean status){
		custPanel.displayChangeStatus(status);
	}

	/**
	 * Reset the can for the customer panel
	 */
	public void resetCan(){
		custPanel.resetCan();
	}
	/**
	 * Check if the customer panel is null
	 * @return
	 */
	public boolean isCustomerPanelTerminated(){
		return (custPanel==null);
	}
	/**
	 * Service to update the can label located at the customer panel
	 */
	public void updateCanLabel(String drinkName) {
		if(drinkName!=null){
			custPanel.setCan(drinkName);
		}		
	}
	/**
	 * Update the drink selection box
	 */
	public void update(int brand, int quantity, int price, String name) {
		custPanel.getDrinkSelectionBox().update(brand, quantity, price, name);
	}

	/**
	 * Set the drink selection box state
	 * @param index
	 * @param active
	 */
	public void setDrinkSelectionBoxState(int index, boolean active){
		custPanel.getDrinkSelectionBox().setState(index, active);
	}
	/**
	 * Set the item state for the drink selection box
	 * @param index
	 * @param active
	 */
	public void setItemState(int index, boolean active){
		custPanel.getDrinkSelectionBox().setItemState(index, active);
	}

}
